@extends('admin.common.app')
@section('css')
    <link rel="stylesheet" href="/admin/css/pagination.css">
@endsection
@section('cont')

    <section class="Hui-article-box">
        <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
            <span class="c-gray en">&gt;</span>
            成绩管理
            <span class="c-gray en">&gt;</span>
            考试信息 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
                <i class="Hui-iconfont">&#xe68f;</i>
            </a>
        </nav>
        <div class="Hui-article">
            <article class="cl pd-20">
                <form action="" method="get" class="text-c"> 考试名称：
                    <input type="text" class="input-text" style="width:250px" placeholder="输入考试名称" id="" name="test_name">
                    <input type="text" class="input-text" style="width:250px" placeholder="输入班级名称" id="" name="class_name">
                    <button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜管理员</button>
                </form>
                <div class="cl pd-5 bg-1 bk-gray mt-20" >
                    <span class="l">
                        <form action="" method="post" >
                            @csrf
                           <button type="submit" class="btn btn-primary radius">
                               <i class="Hui-iconfont">&#xe600;</i>
                               导出考试学生
                           </button>
                        </form>
                    </span>
                </div>
                @include('admin.common.msg')
                <table class="table table-border table-bordered table-bg">
                    <thead>
                    <tr>
                        <th scope="col" colspan="9">考试信息列表</th>
                    </tr>
                    <tr class="text-c">
                        <th >ID</th>
                        <th>考试名称</th>
                        <th>班级名称</th>
                        <th>任课老师</th>
                        <th>班主任</th>
                        <th>科目</th>
                        <th>满分</th>
                        <th>注册时间</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($data as $item)
                        <tr class="text-c">
                            <td>{{$item->id}}</td>
                            <td>{{$item->test_name}}</td>
                            <td>{{$item->class_name}}</td>
                            <td>{{$item->teacher}}</td>
                            <td>{{$item->class_teacher}}</td>
                            <th>{{$item->subject}}</th>
                            <td>{{$item->full_mark}}</td>
                            <td>{{$item->created_at}}</td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
                {{$data->links()}}
            </article>
        </div>
    </section>
@endsection
@section('js')
    <script type="application/javascript">
        $('.delbat').click(function () {
            let url=$(this).attr('href');
            let _token="{{csrf_token()}}";
            const e=$(this).parents('tr');//父级 tr
            layer.confirm('真的删除行么', function(index){
                layer.close(index);

                $.ajax({
                    url,
                    type:'DELETE',
                    data:{_token},
                }).then(({status,msg})=>{
                    if (status == 0){
                        layer.msg(msg, {
                                icon: 2,
                                time:2000,
                                skin: 'layui-layer-molv' //样式类名
                            }, e.remove()//删除父级
                        )
                    }
                });
                //向服务端发送删除指令
            });
            //取消默认事件
            return false;
        });
    </script>
    <script>
        let _token="{{csrf_token()}}"
        // 全选删除
        function datadel() {
            // 询问框
            layer.confirm('您是真的要删除选中的用户吗？', {
                btn: ['确认删除', '思考一下']
            }, () => {
                // 选中的用户
                let ids = $('input[name="id[]"]:checked');
                // 删除的ID
                let id = [];
                // 循环
                $.each(ids, (key, val) => {
                    // dom对象 转为 jquery对象 $(dom对象)
                    // id.push($(val).val());
                    id.push(val.value);
                });
                if (id.length > 0) {
                    // 发起ajax
                    $.ajax({
                        url: "{{ route('admin.admin.delall') }}",
                        data: {id, _token},
                        type: 'DELETE'
                    }).then(ret => {
                        if (ret.status == 0) {
                            layer.msg(ret.msg, {time: 2000, icon: 1}, () => {
                                location.reload();
                            })
                        }
                    })

                }

            });
        }
    </script>
@endsection
